layui.use(['layer','form'],function () {
    var layer = layui.layer
        ,form = layui.form;

    form.verify({
        username:function (value) {
            if(value.length<3){
                return "用户名长度必须大于3位";
            }
        },
        password: [/^[\S]{6,12}$/,'密码必须6到12位，且不能出现空格']
    });

    form.on('submit(*)',function (data) {

      var index =   layer.msg('登录中...', { icon: 16, shade: [0.5, '#f5f5f5'], scrollbar: false, offset: '50%', time: 300000 });

            $.ajax({
                url:data.form.action,
                type:data.form.method,
                data:$(data.form).serialize(),
                success:function (result) {
                    // layer.close(index);
                    var flag = result.flag;
                    if(flag){
                        //登录成功
                        var url = result.data.url;
                        location.href = url;
                    }else{
                        layer.msg(result.message);
                    }
                },
                error:function () {
                    layer.msg("系统异常！");
                }

            })





    })

});

function getVerify(obj) {
    obj.src = "/getVerify?"+Math.random();
}